package com.xuan.yubi.bizmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 创建交换机和消息队列
 */
@Slf4j
public class MqInitMain {
    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        try {
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();
            channel.exchangeDeclare("test_exchange", "direct");
            channel.queueDeclare("test_queue", false, false, false, null);
            channel.queueBind("test_queue", "test_exchange", "test_routingKey");
        } catch (Exception e) {
            log.error("创建交换机和队列失败: ", e);
        }
    }
}
